home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / xenix.c < prev    next >
Text File  |  1985-06-03  |  8KB  |  342 lines

  1. title MSDOS 2.00 Function Library for Lattice C
  2. ;
  3. ;........................................
  4. ;.                    .
  5. ;.    DOS 2.00 Functions for        .
  6. ;.           Lattice            .
  7. ;.                    .
  8. ;.    T. Jennings 23 June 83        .
  9. ;.      created 13 Sept 82        .
  10. ;.                    .
  11. ;........................................
  12. ;
  13. ;MSDOS 2.00 support for Lattice. These will NOT
  14. ;work for version 1.xx of DOS. All support full
  15. ;paths. The function names are the same as the
  16. ;standard library names with "_x" prepended, to
  17. ;accomodate my file system nameing heirarchy.
  18. ;
  19. ;NOTE: You cannot mix these calls with the 
  20. ;Lattice library calls: i.e. open with _xopen()
  21. ;and write with open(). You must use ALL or
  22. ;NONE.
  23. ;
  24. ;These functions all use the DOS buffers. 
  25. ;
  26. ;Detailed info is given in the title block for
  27. ;each function. A quick description follows.
  28. ;
  29. ;handle= _xopen(pathname,access);
  30. ;int handle,access;
  31. ;char *pathname;
  32. ;
  33. ;    Open a file. handle returns either 
  34. ;the DOS handle, or -1 if error (file not 
  35. ;found). Access is: 0 == read only, 1 == write
  36. ;only, 2 == read/write.
  37. ;
  38. ;handle= _xcreate(pathname,access);
  39. ;
  40. ;    Create a new file, delete any existing
  41. ;copy. Access is not used: use 0. Returns the
  42. ;handle or -1 if error.
  43. ;
  44. ;v= _xread(handle,buffer,count);
  45. ;v= _xwrite(handle,buffer,count);
  46. ;int v,handle,count;
  47. ;char *buffer;
  48. ;
  49. ;    File read or write to an opened or
  50. ;created file. reads or writes 'count' bytes
  51. ;to the file 'handle', to or from 'buffer'.
  52. ;Returns the number of bytes processed: equal
  53. ;to 'count' if sucessful.
  54. ;
  55. ;error= _xclose(handle)
  56. ;int error;
  57. ;
  58. ;    Close an open file. Returns -1 if 
  59. ;error. Any buffers are flushed at this point.
  60. ;
  61. ;_xdelete(pathname);
  62. ;
  63. ;    Remove the file from the file
  64. ;system.
  65. ;
  66. ;fsize= _fsize(pathname);
  67. ;long fsize;
  68. ;
  69. ;    Returns the size of the file in bytes.
  70. ;Returns 0 if no file. Do NOT call inbetween
  71. ;calls to _xfind().
  72. ;
  73. ;found= _xfind(pathname,filename,&fsize,attrib,flag);
  74. ;int found,flag,attrib;
  75. ;char *pathname,filename[14];
  76. ;long fsize;
  77. ;
  78. ;Search for the specified pathname. flag should
  79. ;be 0 for the first call, non-zero for all
  80. ;subsequent calls. _xfind() returns true if a
  81. ;match was found, and the found file is 
  82. ;returned in filename[], in ASCIZ format.
  83. ;Attrib is the DOS attributes to match; I
  84. ;will not describe that mess here. _xfind()
  85. ;returns the size of the file in fsize. (Don't
  86. ;forget to pass the address of fsize.)
  87. ; For example:
  88. ;
  89. ;int i;
  90. ;char filename[14];
  91. ;long fsize;
  92. ;
  93. ;    i= 0;
  94. ;    while (_xfind("\\bin\\*.*",filename,&fsize,0,i)) {
  95. ;        printf("File: %14s Size: %lu\n",filename,fsize);
  96. ;        ++i;
  97. ;    }
  98. ;    printf("%u matching files.\n",i);
  99. ;
  100. ;Prints the names of all matching disk files. 
  101. ;Any other calls (except_fsize()) can be made
  102. ;in between calls to _xfind().
  103. ;
  104. dgroup group data
  105. pgroup group prog
  106.  
  107. prog segment byte public 'prog'
  108.  
  109. public    _xopen,_xcreate,_xclose
  110. public    _xread,_xwrite
  111. public    _xfind
  112. public    _fsize
  113. public     _xdelete
  114. assume cs:pgroup,ds:dgroup
  115. ;;
  116. ;;    handle= _xcreate(name,access)
  117. ;;    handle= _xopen(name,access)
  118. ;;
  119. ;;    int handle;        -1 if error,
  120. ;;    int access;        0=r, 1=w, 2=r/w
  121. ;;    char *name;        null terminated
  122. ;;
  123. ;;Open and create functions. The name is a null
  124. ;;terminated string. The access byte is passed
  125. ;;directly to DOS. All errors are translated to
  126. ;;a -1 return value.
  127. ;;
  128. _xopen proc near
  129.     mov    ah,61
  130.     jmp    short opncrt
  131. _xcreate proc near
  132.     mov    ah,60
  133.  
  134. opncrt:    push    bp
  135.     mov    bp,sp
  136.     mov    dx,[bp+4]    ;pathname,
  137.     mov    al,[bp+6]    ;access,
  138.     xor    bx,bx
  139.     xor    cx,cx
  140.     int    21h        ;do it,
  141.     jnc    opncrt1
  142.     mov    ax,-1        ;error!
  143. opncrt1:pop    bp
  144.     ret
  145.  
  146. _xcreate endp
  147. _xopen endp
  148. ;;
  149. ;;xclose(handle)
  150. ;;int handle;
  151. ;;
  152. ;;Close a handle opened by XOPEN or XCREATE.
  153. ;;Returns -1 if close error.
  154. ;;
  155. _xclose proc near
  156.     mov    ah,62
  157.     push    bp
  158.     mov    bp,sp
  159.     mov    bx,[bp+4]    ;handle,
  160.     int    21h
  161.     pop    bp
  162.     ret
  163.  
  164. _xclose endp
  165. page
  166. ;;
  167. ;;    count= xread(handle,buffer,size)
  168. ;;    count= xwrite(handle,buffer,size)
  169. ;;
  170. ;;    int count;    bytes actually r/w
  171. ;;    int handle;
  172. ;;    char *buffer;
  173. ;;    int size;    byte count,
  174. ;;
  175. ;;    Read or write (size) bytes from the
  176. ;;file (handle). The return value is the number 
  177. ;;of bytes actually processed.
  178. ;;
  179. ;;    No text translation is done. All
  180. ;;bytes are processed as read or written. No
  181. ;;check is done (or is possible) on the buffer
  182. ;;size.
  183. ;;
  184. _xread proc near
  185.     mov    ah,63
  186.     jmp    short rdwrt
  187. _xwrite proc near
  188.     mov    ah,64
  189.  
  190. rdwrt:    push    bp
  191.     mov    bp,sp
  192.     mov    bx,[bp+4]    ;handle,
  193.     mov    cx,[bp+8]    ;count,
  194.     mov    dx,[bp+6]    ;buffer,
  195.     int    21h
  196.     pop    bp
  197.     ret
  198.  
  199. _xwrite endp
  200. _xread endp
  201. page
  202. ;;
  203. ;;    ret= xfind(path,name,size,attrib,first)
  204. ;;    int ret;        0 if no match
  205. ;;    char *path;
  206. ;;    char *name;        dest name,
  207. ;;    long *size;        ptr to file siz
  208. ;;    int attrib;        attributes
  209. ;;    int first;        0 if 1st time,
  210. ;;
  211. ;;Find the Nth occurence of pathname. Returns
  212. ;;0 when no match. Only the filename portion
  213. ;;can contain wildcards. The returned filename
  214. ;;does not contain the path portion of the 
  215. ;;input string.
  216. ;;    Not recursive. Do not call _FSIZE
  217. ;;inbetween _XFIND calls.
  218. ;;
  219. xfpath    equ    4    ;path pointer,
  220. xfname    equ    6    ;retnd name,
  221. xfsize    equ    8    ;file size ptr,
  222. xfaccess equ    10    ;access,
  223. xfflag    equ    12    ;first time flag,
  224.  
  225. _xfind proc near
  226.     push    bp
  227.     mov    bp,sp
  228.     mov    ah,26        ;set DMA addr
  229.     mov    dx,offset dgroup:xfbuf
  230.     int    21h        ;to buffer,
  231.     test word ptr [bp+xfflag],-1
  232.     mov    ah,78        ;do right call,
  233.     jz    xf1
  234.     mov    ah,79        ;0 == 1st time,
  235. xf1:    mov    dx,[bp+xfpath]    ;path name,
  236.     mov    cx,[bp+xfaccess];access,
  237.     int    21h
  238.     mov    ax,0        ;ret if no
  239.     jc    xfr        ;match,
  240. ;
  241. ;Copy the file size in.
  242. ;
  243.     mov    bx,[bp+xfsize]    ;size ptr,
  244.     mov    ax,fsize
  245.     mov    [bx],ax
  246.     mov    ax,fsize+2
  247.     mov    [bx+2],ax
  248.  
  249.     mov    di,[bp+xfname]    ;dest string,
  250.     mov    si,offset dgroup:fname
  251.     mov    cx,12
  252.     cld
  253. ;
  254. ;Fix a "slight" XENIX bug: Delete trailing 
  255. ;spaces, else it fails OPENs.
  256. ;
  257. xf2:    lodsb            ;get a byte,
  258.     cmp    al,0        ;if null
  259.     je    xf3
  260.     cmp    al,' '        ;or space,
  261.     je    xf3        ;stop,
  262.     stosb
  263.     loop    xf2        ;max 11 chars    
  264. xf3:    mov byte ptr [di],0    ;terminate,
  265.     mov    ax,1        ;good return.
  266. xfr:    pop    bp
  267.     ret
  268. _xfind endp
  269. page
  270. ;;
  271. ;;    fsize= _fsize(filename)
  272. ;;    long fsize;
  273. ;;    char *filename;
  274. ;;
  275. ;;Return the size of a file, in bytes. Returns
  276. ;;0 if file not found. Filename can contain
  277. ;;a path.
  278. ;;
  279. ;;Cannot be called in between any _XFIND calls.
  280. ;;
  281. _fsize proc near
  282.     push    bp
  283.     mov    bp,sp
  284.     mov    ah,26        ;set DMA addr
  285.     mov    dx,offset dgroup:xfbuf
  286.     int    21h        ;to buffer,
  287.     mov    ah,78        ;search 1st,
  288. xs1:    mov    dx,[bp+4]    ;path name,
  289.     mov    cx,0
  290.     int    21h
  291.     mov    ax,0        ;ret if no
  292.     mov    bx,0        ;match,
  293.     jc    xsr
  294.  
  295.     mov    bx,fsize
  296.     mov    ax,fsize+2
  297. xsr:    pop    bp
  298.     ret
  299. _fsize endp
  300. page
  301. ;
  302. ;error= _xdelete(path);
  303. ;int error;
  304. ;char *path;
  305. ;
  306. _xdelete proc near
  307.     push    bp
  308.     mov    bp,sp
  309.     mov    dx,[bp+4]
  310.     mov    ah,41h
  311.     int    21h
  312.     mov    ax,0
  313.     sbb    ax,0
  314.     pop    bp
  315.     ret
  316. _xdelete endp
  317.  
  318. prog ends
  319. page
  320. data segment word public 'data'
  321. ;
  322. ;Structure for the FindFirst and FindNext
  323. ;function XFIND. NOT REENTRANT.
  324. ;
  325. xfbuf    db    (?)    ;search attrib
  326.     db    (?)    ;drive,
  327.     db 11 dup (?)    ;name,
  328.     dw    (?)    ;last ent
  329.     dd    (?)    ;DPB,
  330.     dw    (?)    ;dir start
  331.  
  332.     db    (?)    ;attrib found,
  333.     dw    (?)    ;time?
  334.     dw    (?)    ;date?
  335. fsize    dw    (?)    ;size low
  336.     dw    (?)    ;size hi,
  337. fname    db 13 dup (?)    ;packed name,
  338.  
  339. data ends    
  340.  
  341.     end
  342.